package com.company.gas.controller;

import com.company.gas.pojo.Repair;
import com.company.gas.service.IRepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/Repair")
@Api(tags = "安检维修相关接口")
public class RepairController {
    @Autowired
    private IRepairService iRepairService;

    //查询全部维修信息
    @GetMapping("/queryRepairList")
    @ApiOperation("查询全部维修信息")
    public List<Repair> queryRepairList(){
        List<Repair> repairList = iRepairService.queryRepairList();
        return repairList;
    }

    //查询指定编号对应维修信息
    @GetMapping("/queryRepairById")
    @ApiOperation("查询指定ID维修信息")
    public Repair queryRepairById(@RequestParam(value = "报装编号") String repId){
        Repair repair = iRepairService.queryRepairById(repId);
        System.out.println(repair);
        return repair;
    }

    //添加一个维修信息
    @GetMapping("/addRepair")
    @ApiOperation("添加一个维修信息")
    public String addRepair(@RequestParam(value = "维修编号") String repId, @RequestParam(value = "客户ID") String cusId,
                            @RequestParam(value = "员工ID") String staffId,
                            @RequestParam(value = "维修日期") Date repDate, @RequestParam(value = "标识位") Integer flag,
                            @RequestParam(value = "创建时间") Date createTime, @RequestParam(value = "创建人") String createBy,
                            @RequestParam(value = "修改时间") Date modifyTime, @RequestParam(value = "修改人") String modifyBy){
        int isAddRepair = iRepairService.addRepair(repId,cusId,staffId,repDate,flag,createTime,createBy,modifyTime,modifyBy);
        if(isAddRepair == 1){
            return "add success";
        }else {
            return "add fail";
        }
    }

    //修改一个维修信息
    @GetMapping("/updateRepair")
    @ApiOperation("修改一个维修信息")
    public String updateRepair(@RequestParam(value = "客户ID") String cusId,
                               @RequestParam(value = "员工ID") String staffId,
                               @RequestParam(value = "维修日期") Date repDate,
                               @RequestParam(value = "修改时间") Date modifyTime, @RequestParam(value = "修改人") String modifyBy){
        int isUpdateRepair = iRepairService.updateRepair(cusId,staffId,repDate,modifyTime,modifyBy);
        if(isUpdateRepair == 1){
            return "update success";
        }else {
            return "update fail";
        }
    }

    //删除指定编号维修信息
    @GetMapping("/deleteRepair")
    @ApiOperation("删除指定编号维修信息")
    public String deleteRepair(@RequestParam(value = "报装编号") String repId){
        int isDeleteRepair = iRepairService.deleteRepair(repId);
        if(isDeleteRepair == 1){
            return "delete success";
        }else {
            return "delete fail";
        }
    }
}